﻿using Microsoft.AspNetCore.Mvc;
using yunbo.Model.BIW;
using yunbo.Repositorys.BIWRepositorys;

namespace yunbo.Controllers.BIWControllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class Wbd_kwController : Controller
    {
        Wbd_kwRepository wbd_KwRepository = new Wbd_kwRepository();

        [HttpGet("GetFYWbd_kw")]
        public IActionResult GetFYWbd_kw(int PageNumber, int PageSize)
        {
            FYWbd_kw fYwbd_Kw = wbd_KwRepository.GetfYWbd_Kw(PageNumber, PageSize);
            return Ok(fYwbd_Kw);
        }
        [HttpPost("AddWbd_kw")]
        public IActionResult AddWbd_kw(TJWbd_kw tJWbd_Kw)
        {
            // 获取当前时间，并格式化为字符串
            string currentTime = DateTime.Now.ToString("yyyyMMdd");

            // 生成一个四位随机数
            Random random = new Random();
            int randomNumber = random.Next(1000, 10000); // 生成1000到9999之间的随机数
            string randomNumberString = randomNumber.ToString("D4"); // 格式化为四位数字字符串

            // 组合当前时间和随机数生成ID
            string code = $"kw{currentTime}{randomNumberString}";
            Wbd_kw kw = new Wbd_kw()
            {
                kw_code = code,
                kw_name=tJWbd_Kw.kw_name,
                kw_zt=1,
                kw_mj=tJWbd_Kw.kw_mj,
                kw_zzl=tJWbd_Kw.kw_zzl,
                kw_x=tJWbd_Kw.kw_x,
                kw_y=tJWbd_Kw.kw_y,
                kw_z=tJWbd_Kw.kw_z,
                kw_ssck=tJWbd_Kw.kw_ssck,
                kw_sskq=tJWbd_Kw.kw_sskq,
                bz=tJWbd_Kw.bz,
                is_deleted=1,
                create_by=tJWbd_Kw.create_by,
                create_time=DateTime.Now,
            };
            bool kws= wbd_KwRepository.AddWbd_kw(kw)>0;
            return Ok(kws);
        }
        [HttpPut("UpWbd_kw")]
        public IActionResult UpWbd_kw(XGWbd_kw xGWbd_Kw)
        {
            Wbd_kw kw = new Wbd_kw()
            { 
                kw_id=xGWbd_Kw.kw_id,
                kw_code=xGWbd_Kw.kw_code,
                kw_name=xGWbd_Kw.kw_name,
                kw_mj=xGWbd_Kw.kw_mj,
                kw_zzl=xGWbd_Kw.kw_zzl,
                kw_x=xGWbd_Kw.kw_x,
                kw_y=xGWbd_Kw.kw_y,
                kw_z=xGWbd_Kw.kw_z,
                kw_ssck=xGWbd_Kw.kw_ssck,
                kw_sskq=xGWbd_Kw.kw_sskq,
                bz=xGWbd_Kw.bz,
                update_by=xGWbd_Kw.update_by,
                update_time=DateTime.Now,
            };
            bool kws=wbd_KwRepository.UpWbd_kw(kw)>0;
            return Ok(kws);
        }
        [HttpPut("IsDeWbd_kw")]
        public IActionResult IsDeWbd_kw(int id)
        {
            bool kw=wbd_KwRepository.IsDeWbd_kw(id)>0;
            return Ok(kw);
        }
        [HttpPut("UpZt")]
        public IActionResult UpZt(int id , int zt)
        {
            bool kw=wbd_KwRepository.UpZt(id,zt)>0;
            return Ok(kw);
        }
        [HttpGet("Getkw")]
        public IActionResult Getkw(string code)
        {
            List<Wbd_kw> wbd_Kws= wbd_KwRepository.Getkw(code);
            return Ok(wbd_Kws);
        }
    }
}
